import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Demo(QWidget):
    def __init__(self,parent=None):
        super(Demo,self).__init__(parent)
        self.setWindowTitle("paint设置背景")
    def paintEvent(self,event):
        painter=QPainter(self)
        # painter.setBrush(Qt.green)
        # painter.drawRect(self.rect())
        pixmap=QPixmap('panda.jpg')
        painter.drawPixmap(self.rect(),pixmap)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=Demo()
    win.show()
    sys.exit(app.exec_())